/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef FREE_CAMERA_H_INCLUDED
#define FREE_CAMERA_H_INCLUDED

#ifndef WX_PCH_H_INCLUDED
#include "wx_pch.h"
#endif
#include "property_manager.h"

#include "math/matrix.h"

class FreeCamera
{
private:
    float m_sensibilityX, m_sensibilityY;
    float m_moveSensiX, m_moveSensiY, m_moveSensiUp;
    float m_pitchMax;

    float m_x, m_y, m_z;
    float m_yaw,m_pitch,m_roll;
    math::matrix4f mat;

    void init();
public:
    FreeCamera();
    FreeCamera(const FreeCamera &copy);
    FreeCamera& operator=(const FreeCamera &copy);
    ~FreeCamera();

    void moveTo( math::vector3f pos);
    math::vector3f getPosition()
    {
        return math::vector3f(m_x, m_y, m_z);
    }

    void addAbsoluteDelta(math::vector3f pos);
    void addRelatifDelta(math::vector3f pos);
    void addKeyboardMove( int forward, int right, int up);

    void setOrientation( float yaw, float pitch, float roll);

    void addToOrientation( float yaw, float pitch, float roll);

    void updateCamera();
    void addMouseOrientation( float mouse_x, float mouse_y);

    void apply();

    math::matrix4f getMatrix()
    {
        return mat;
    }
private:
    math::quaternionf eulerToQuat( float yaw, float pitch, float roll);
    void quatToEuler( math::quaternionf quat, float &yaw, float &pitch, float &roll);
};

#endif // FREE_CAMERA_H_INCLUDED
